package heima.test.demo4;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Data
public class Liquid {
    private String name;
    private int weight;
    private int value;
    private int unitValue;

    public Liquid(String name, int weight, int value){
        this.name = name;
        this.value = value;
        this.weight = weight;
        this.unitValue = value / weight;
    }

    public static void main(String[] args){
        List<Liquid> liquidList = new ArrayList<>();
        liquidList.add(new Liquid("水",4,24));
        liquidList.add(new Liquid("牛奶",8,160));
        liquidList.add(new Liquid("五粮液",2,4000));
        liquidList.add(new Liquid("可乐",6,108));
        liquidList.add(new Liquid("茅台",1,4000));

        liquidList.sort((o1, o2) -> (-o1.getUnitValue() + o2.getUnitValue()));
        int maxWeight = 10;
        int maxValue = 0;
        for(Liquid liquid : liquidList){
            int weight = 0;
            if(liquid.getWeight() < maxWeight){
                weight = liquid.getWeight();
            } else {
                weight = maxWeight;
            }
            System.out.println("选择"+liquid.getWeight()+"升"+liquid.getName());
            maxWeight -= weight;
            maxValue += weight * liquid.unitValue;
            if(maxWeight == 0){
                break;
            }
        }
        System.out.println("最大价值为"+maxValue);

    }
}
